﻿document.observe("dom:loaded", loadMain);
var checkbtn_0, checkbtn_1, checkbtn_2, checkbtn_4, checkbtn_5;
function loadMain() {
    
    initForPayment();
    addEventFocus_LostFocus();    
};


function addEventFocus_LostFocus() {
    //Giao the tan nha
    if ($("txtName_0")) {
        $("txtName_0").onfocus = setTxtFocus;
        $("txtName_0").onblur = setTxtLostFocus;
    }
    if ($("txtPhone_0")) {
        $("txtPhone_0").onfocus = setTxtFocus;
        $("txtPhone_0").onblur = setTxtLostFocus;
    }
    if ($("txtSoNha_0")) {
        $("txtSoNha_0").onfocus = setTxtFocus;
        $("txtSoNha_0").onblur = setTxtLostFocus;
    }
    if ($("txtDuong_0")) {
        $("txtDuong_0").onfocus = setTxtFocus;
        $("txtDuong_0").onblur = setTxtLostFocus;
    }
    if ($("txtWard_0")) {
        $("txtWard_0").onfocus = setTxtFocus;
        $("txtWard_0").onblur = setTxtLostFocus;
    }
    if ($("ddlDist0")) {
        $("ddlDist0").onfocus = setTxtFocus;
        $("ddlDist0").onblur = setTxtLostFocus;
    }
    if ($("txtBuilding_0")) {
        $("txtBuilding_0").onfocus = setTxtFocus;
        $("txtBuilding_0").onblur = setTxtLostFocus;
    }
    if ($("txtDesc_0")) {
        $("txtDesc_0").onfocus = setTxtFocus;
        $("txtDesc_0").onblur = setTxtLostFocus;
    }
    //Tra bang the ATM
    if ($("txtName_1")) {
        $("txtName_1").onfocus = setTxtFocus;
        $("txtName_1").onblur = setTxtLostFocus;
    }
    if ($("txtPhone_1")) {
        $("txtPhone_1").onfocus = setTxtFocus;
        $("txtPhone_1").onblur = setTxtLostFocus;
    }
    if ($("txtSoNha_1")) {
        $("txtSoNha_1").onfocus = setTxtFocus;
        $("txtSoNha_1").onblur = setTxtLostFocus;
    }
    if ($("txtSoNha_1")) {
        $("txtSoNha_1").onfocus = setTxtFocus;
        $("txtSoNha_1").onblur = setTxtLostFocus;
    }
    if ($("txtDuong_1")) {
        $("txtDuong_1").onfocus = setTxtFocus;
        $("txtDuong_1").onblur = setTxtLostFocus;
    }
    if ($("txtWard_1")) {
        $("txtWard_1").onfocus = setTxtFocus;
        $("txtWard_1").onblur = setTxtLostFocus;
    }
    if ($("ddlDist1")) {
        $("ddlDist1").onfocus = setTxtFocus;
        $("ddlDist1").onblur = setTxtLostFocus;
    }
    if ($("txtBuilding_1")) {
        $("txtBuilding_1").onfocus = setTxtFocus;
        $("txtBuilding_1").onblur = setTxtLostFocus;
    }
    if ($("txtDesc_1")) {
        $("txtDesc_1").onfocus = setTxtFocus;
        $("txtDesc_1").onblur = setTxtLostFocus;
    }
    //Nhận thẻ tại NhomMua
    if ($("txtName_2")) {
        $("txtName_2").onfocus = setTxtFocus;
        $("txtName_2").onblur = setTxtLostFocus;
    }
    if ($("txtPhone_2")) {
        $("txtPhone_2").onfocus = setTxtFocus;
        $("txtPhone_2").onblur = setTxtLostFocus;
    }
    if ($("txtDesc_2")) {
        $("txtDesc_2").onfocus = setTxtFocus;
        $("txtDesc_2").onblur = setTxtLostFocus;
    }
    //Thẻ ATM nội địa
    if ($("txtName_4")) {
        $("txtName_4").onfocus = setTxtFocus;
        $("txtName_4").onblur = setTxtLostFocus;
    }
    if ($("txtPhone_4")) {
        $("txtPhone_4").onfocus = setTxtFocus;
        $("txtPhone_4").onblur = setTxtLostFocus;
    }
    if ($("txtDesc_4")) {
        $("txtDesc_4").onfocus = setTxtFocus;
        $("txtDesc_4").onblur = setTxtLostFocus;
    } 
}
/*end load function main*/
/***************************************************************/
function initForPayment() {
    if ($("aPTTT_0")) {
        checkbtn_0 = $("aPTTT_0").select('i')[0];
        checkbtn_1 = $("aPTTT_1").select('i')[0];
        checkbtn_2 = $("aPTTT_2").select('i')[0];
        checkbtn_4 = $("aPTTT_4").select('i')[0];
        checkbtn_5 = $("aPTTT_5").select('i')[0];
        
        $("aPTTT_0").onclick = showFormBuy;
        $("aPTTT_1").onclick = showFormBuy;
        $("aPTTT_2").onclick = showFormBuy;
        //$("aPTTT_3").onclick = showFormBuy; trong layout khong co

        if ($("btnTT_4")) {
            $("aPTTT_4").onclick = showFormBuy;
            $("aPTTT_5").onclick = showFormBuy;
        }
        $("btnTT_0").onclick = BuyDeals;  


        try {
            if ($("btnTT_2")) $("btnTT_2").onclick = BuyDeals;
            if ($("btnTT_1")) $("btnTT_1").onclick = BuyDeals;
            if ($("btnTT_4")) $("btnTT_4").onclick = BuyDeals;
            if ($("btnTT_5")) $("btnTT_5").onclick = BuyDeals;


            $("aPTTT_0").childNodes[0].className = "checkbtn";
//            $("aPTTT_1").className = "aCerditMH";
//            $("aPTTT_2").className = "aCerditMH";
//            if ($("btnTT_4")) {
//                $("aPTTT_4").className = "aCerditMH";
//                $("aPTTT_5").className = "aCerditMH";
//            }
            if (strPT == "2") {
                iPTTT = strPT;
                setNoneAllPTTT();
                checkbtn_2.addClassName('checked');
                $("liPTTT_2").style.display = "block";

            } else if (strPT == "1") {
                iPTTT = strPT;
                setNoneAllPTTT();
                checkbtn_1.addClassName('checked');                
               
                if (strPTDetail == "1" || strPTDetail == '') {
                    $("liGift_1").style.display = "none";
                    $("liNoGift_1").style.display = "block";
                    $("cbGift_1").checked = false;           
                }
                else {
                    $("liNoGift_1").style.display = "none";
                    $("liGift_1").style.display = "block";
                    $("cbGift_1").checked = true; //add 04/06/2011
                    if ($("btnTT_1Gift")) $("btnTT_1Gift").onclick = BuyDeals; //edit 01/06/2011s                    
                }              
            }
            else if (strPT == "4") {
            iPTTT = strPT;
            setNoneAllPTTT();
            checkbtn_4.addClassName('checked');   
                if (strPTDetail == "4" || strPTDetail == '') {
                    $("liGift_4").style.display = "none";
                    $("liNoGift_4").style.display = "block";                    
                    $("cbGift_4").checked = false;
                }
                else {
                    $("liNoGift_4").style.display = "none";
                    $("liGift_4").style.display = "block";
                    if ($("btnTT_4Gift")) $("btnTT_4Gift").onclick = BuyDeals; 
                    $("cbGift_4").checked = true;
                }                
            }
            else if (strPT == "5") {
                iPTTT = strPT;
                setNoneAllPTTT();
                checkbtn_5.addClassName('checked');
                if (strPTDetail == "7" || strPTDetail == '') {
                    $("liGift_5").style.display = "none";
                    $("liNoGift_5").style.display = "block";
                    $("cbGift_5").checked = false;
                    
                }
                else {
                    $("liGift_5").style.display = "block";
                    $("liNoGift_5").style.display = "none";
                    if ($("btnTT_5Gift")) $("btnTT_5Gift").onclick = BuyDeals; 
                    $("cbGift_5").checked = true; 
                    
                }                
                
            }
            else {                
                iPTTT = 0;
                setNoneAllPTTT();
                checkbtn_0.addClassName('checked');
                $("liPTTT_0").style.display = "block";
                
            }
        } catch (ex) { }

    }
    else if ($("aPTTTHN_0")) {
        checkbtn_0 = $("aPTTTHN_0").select('i')[0];
        checkbtn_1 = $("aPTTTHN_1").select('i')[0];
        checkbtn_2 = $("aPTTTHN_2").select('i')[0];
        checkbtn_4 = $("aPTTTHN_4").select('i')[0];
        checkbtn_5 = $("aPTTTHN_5").select('i')[0];
    
        $("aPTTTHN_0").onclick = showFormBuy_HN;
        $("aPTTTHN_1").onclick = showFormBuy_HN;
        $("aPTTTHN_2").onclick = showFormBuy_HN;        
        if ($("btnTTHN_4")) {
            $("aPTTTHN_4").onclick = showFormBuy_HN;
            $("aPTTTHN_5").onclick = showFormBuy_HN;
        }
        
        $("btnTTHN_0").onclick = BuyDeals_HN;
        
        try {
           
            if ($("btnTTHN_2")) $("btnTTHN_2").onclick = BuyDeals_HN;
            if ($("btnTTHN_1")) $("btnTTHN_1").onclick = BuyDeals_HN;
            if ($("btnTTHN_4")) {
                if ($("btnTTHN_4")) $("btnTTHN_4").onclick = BuyDeals_HN;
                if ($("btnTTHN_5")) $("btnTTHN_5").onclick = BuyDeals_HN;
            }
			
			 if (strPT == "2") {
                iPTTT = strPT;
                setNoneAllPTTT_HN();
                checkbtn_2.addClassName('checked');
                $("liPTTT_2").style.display = "block";

            } else if (strPT == "1") {
                iPTTT = strPT;
                setNoneAllPTTT_HN();
                checkbtn_1.addClassName('checked');                
               
                if (strPTDetail == "1" || strPTDetail == '') {
                    $("liGift_1").style.display = "none";
                    $("liNoGift_1").style.display = "block";
                    $("cbGift_1").checked = false;           
                }
                else {
                    $("liNoGift_1").style.display = "none";
                    $("liGift_1").style.display = "block";
                    $("cbGift_1").checked = true; 
                    if ($("btnTTHN_1Gift")) $("btnTTHN_1Gift").onclick = BuyDeals_HN;             
                }              
            }
            else if (strPT == "4") {
            iPTTT = strPT;
            setNoneAllPTTT_HN();
            checkbtn_4.addClassName('checked');   
                if (strPTDetail == "4" || strPTDetail == '') {
                    $("liGift_4").style.display = "none";
                    $("liNoGift_4").style.display = "block";                    
                    $("cbGift_4").checked = false;
                }
                else {
                    $("liNoGift_4").style.display = "none";
                    $("liGift_4").style.display = "block";
                    if ($("btnTTHN_4Gift")) $("btnTTHN_4Gift").onclick = BuyDeals_HN; 
                    $("cbGift_4").checked = true;
                }                
            }
            else if (strPT == "5") {
                iPTTT = strPT;
                setNoneAllPTTT_HN();
                checkbtn_5.addClassName('checked');
                if (strPTDetail == "7" || strPTDetail == '') {
                    $("liGift_5").style.display = "none";
                    $("liNoGift_5").style.display = "block";
                    $("cbGift_5").checked = false;
                    
                }
                else {
                    $("liNoGift_5").style.display = "none";
                    $("liGift_5").style.display = "block";
                    if ($("btnTTHN_5Gift")) $("btnTTHN_5Gift").onclick = BuyDeals_HN; 
                    $("cbGift_5").checked = true; 
                    
                }                
                
            }
            else {                
                iPTTT = 0;
                setNoneAllPTTT_HN();
                checkbtn_0.addClassName('checked');
                $("liPTTT_0").style.display = "block";
                
            }

        } catch (ex) { }
    }
	
}
/***************************************************************/
function BuyDeals(e) {
    var eID = utils.getElementFireEvent(e);
    var flag = 0;
    var iIndex = eID.id.split("_")[1]; 
    
    
    iIndex = parseInt(iIndex);
    
    
    
    var strIndex = eID.id.split("_")[1];
    switch (iIndex) {
        case 0:
            //$("txtName_" + iIndex).value = trim($("txtName_" + iIndex).value);
            //$("txtSoNha_" + iIndex).value = trim($("txtSoNha_" + iIndex).value);
            //$("txtDuong_" + iIndex).value = trim($("txtDuong_" + iIndex).value);
            $("txtPhone_" + iIndex).value = trim($("txtPhone_" + iIndex).value);

            if (trim($("txtName_" + iIndex).value).length == 0) {
                flag = 1;
            } 
            
            //No.1 21/10
            else if (checkPhone($("txtPhone_" + iIndex).value) == false) {
                $("eMess_" + strIndex).innerHTML = langMess()[0][10];
                return;
            }           
            //No.1 21/10 End
             
            else if (trim($("txtSoNha_" + iIndex).value).length == 0) {
                flag = 1;
            }
            else if (trim($("txtDuong_" + iIndex).value).length == 0) {
                flag = 1;
            }
            else if ($("txtPhone_" + iIndex).value.length == 0) {
                flag = 1;
            }
            
            if ($("ddlDist" + iIndex)) {
                if ($("ddlDist" + iIndex).selectedIndex == 0) {
                    flag = 1;
                }
            }
            else {
                if (trim($("txtQuanHidden_0").value).length == 0)
                    flag = 1;
            }
            break;
        case 1:
            if ($("cbGift_1").checked) {
                if (trim($("txtName_1a").value).length == 0)
                    flag = 1;
                else if (trim($("txtSoNha_1a").value).length == 0)
                    flag = 1;
                else if (trim($("txtDuong_1a").value).length == 0)
                    flag = 1;
                else if (trim($("txtName_1b").value).length == 0)
                    flag = 1;
                else if (trim($("txtSoNha_1b").value).length == 0)
                    flag = 1;
                else if (trim($("txtDuong_1b").value).length == 0)
                    flag = 1;

                if ($("dQuanDDL_1")) {//truong hop chua co dia chi trong user_location                   
                    if ($("ddlDist1a").value == "0")
                        flag = 1;
                    if ($("ddlDist1b").value == "0")
                        flag = 1;
                }
                else {//truong hop da co dia chi trong table user_location
                    if (trim($("txtQuanHidden_1a").value).length == 0)
                        flag = 1;
                    if (trim($("txtQuanHidden_1b").value).length == 0)
                        flag = 1;
                }
                
                if (checkPhone($("txtPhone_1a").value) == false) {
                    $("eMess_1Gift").innerHTML = langMess()[0][10];
                    return;
                } else if (checkPhone($("txtPhone_1b").value) == false) {
                    $("eMess_1Gift").innerHTML = langMess()[0][10];
                    return;
                }


            }
            else {

                if (trim($("txtName_1").value).length == 0)
                    flag = 1;
                
                //No.2 21/10
                else if (checkPhone($("txtPhone_" + iIndex).value) == false) {
                    $("eMess_" + strIndex).innerHTML = langMess()[0][10];
                    return;
                }           
                //No.2 21/10 End
                
                else if (trim($("txtSoNha_1").value).length == 0)
                    flag = 1;
                else if (trim($("txtDuong_1").value).length == 0)
                    flag = 1;
                if ($("dQuanDDL_1")) {//truong hop chua co dia chi trong user_location                
                    if ($("ddlDist1").value == "0")
                        flag = 1;
                }
                else {//truong hop da co dia chi trong table user_location
                    if (trim($("txtQuanHidden_1").value).length == 0)
                        flag = 1;
                }
            }
            break;
        case 2:
            //$("txtName_" + iIndex).value = trim($("txtName_" + iIndex).value);
            $("txtPhone_" + iIndex).value = trim($("txtPhone_" + iIndex).value);
            if (trim($("txtName_" + iIndex).value).length == 0) {
                flag = 1;
            } else if ($("txtPhone_" + iIndex).value.length == 0) {
                flag = 1;
            }
            //No.3 21/10
            else if (checkPhone($("txtPhone_" + iIndex).value) == false) {
                $("eMess_" + strIndex).innerHTML = langMess()[0][10];
                return;
            }           
            //No.3 21/10 End
                
            break;
        case 4:
            if ($("cbGift_4").checked) {               
                if (trim($("txtName_4a").value).length == 0)
                    flag = 1;
                else if (trim($("txtSoNha_4a").value).length == 0)
                    flag = 1;
                else if (trim($("txtDuong_4a").value).length == 0)
                    flag = 1;
                else if (trim($("txtName_4b").value).length == 0)
                    flag = 1;
                else if (trim($("txtSoNha_4b").value).length == 0)
                    flag = 1;
                else if (trim($("txtDuong_4b").value).length == 0)
                    flag = 1;

                if ($("dQuanDDL_4")) {//truong hop chua co dia chi trong user_location
                    if ($("ddlDist4a").value == "0")
                        flag = 1;
                    if ($("ddlDist4b").value == "0")
                        flag = 1;
                }
                else {//truong hop da co dia chi trong table user_location
                    if (trim($("txtQuanHidden_4a").value).length == 0)
                        flag = 1;
                    if (trim($("txtQuanHidden_4b").value).length == 0)
                        flag = 1;
                }

                if (checkPhone($("txtPhone_4a").value) == false) {
                    $("eMess_4Gift").innerHTML = langMess()[0][10];
                    return;
                } else if (checkPhone($("txtPhone_4b").value) == false) {
                    $("eMess_4Gift").innerHTML = langMess()[0][10];
                    return;
                }


            }
            else {
                if (trim($("txtName_4").value).length == 0)
                    flag = 1;
                    
                //No.4 21/10
                else if (checkPhone($("txtPhone_" + iIndex).value) == false) {
                    $("eMess_" + strIndex).innerHTML = langMess()[0][10];
                    return;
                }           
                //No.4 21/10 End
                
                else if (trim($("txtSoNha_4").value).length == 0)
                    flag = 1;
                else if (trim($("txtDuong_4").value).length == 0)
                    flag = 1;
                if ($("dQuanDDL_4")) {//truong hop chua co dia chi trong user_location
                    if ($("ddlDist4").value == "0")
                        flag = 1;
                }
                else {//truong hop da co dia chi trong table user_location
                    if (trim($("txtQuanHidden_4").value).length == 0)
                        flag = 1;
                }
            }
            break;
        case 5:
            if ($("cbGift_5").checked) {
                if (trim($("txtName_5a").value).length == 0)
                    flag = 1;
                else if (trim($("txtSoNha_5a").value).length == 0)
                    flag = 1;
                else if (trim($("txtDuong_5a").value).length == 0)
                    flag = 1;
                else if (trim($("txtName_5b").value).length == 0)
                    flag = 1;
                else if (trim($("txtSoNha_5b").value).length == 0)
                    flag = 1;
                else if (trim($("txtDuong_5b").value).length == 0)
                    flag = 1;

                if ($("dQuanDDL_5")) {//truong hop chua co dia chi trong user_location
                    if ($("ddlDist5a").value == "0")
                        flag = 1;
                    if ($("ddlDist5b").value == "0")
                        flag = 1;
                }
                else {//truong hop da co dia chi trong table user_location
                    if (trim($("txtQuanHidden_5a").value).length == 0)
                        flag = 1;
                    if (trim($("txtQuanHidden_5b").value).length == 0)
                        flag = 1;
                }

                if (checkPhone($("txtPhone_5a").value) == false) {
                    $("eMess_5Gift").innerHTML = langMess()[0][10];
                    return;
                } else if (checkPhone($("txtPhone_5b").value) == false) {
                    $("eMess_5Gift").innerHTML = langMess()[0][10];
                    return;
                }

            }
            else {
                if (trim($("txtName_5").value).length == 0)
                    flag = 1;
                    
                //No.5 21/10
                else if (checkPhone($("txtPhone_" + iIndex).value) == false) {
                    $("eMess_" + strIndex).innerHTML = langMess()[0][10];
                    return;
                }           
                //No.5 21/10 End
                
                else if (trim($("txtSoNha_5").value).length == 0)
                    flag = 1;
                else if (trim($("txtDuong_5").value).length == 0)
                    flag = 1;
                if ($("dQuanDDL_5")) {//truong hop chua co dia chi trong user_location
                    if ($("ddlDist5").value == "0")
                        flag = 1;
                }
                else {//truong hop da co dia chi trong table user_location
                    if (trim($("txtQuanHidden_5").value).length == 0)
                        flag = 1;
                }
            }
            break;
    }

    
        if (flag == 1) 
        {
            $("eMess_" + strIndex).innerHTML = langMess()[0][5];
        }
        else 
        {
                   
            var st = getQueryStringValue("st");
            var idsp = getQueryStringValue("id");
            //$('form1').action = "?st=" + st + "&id=" + idsp + "&pt=" + iIndex;
            var strUrlLocation = window.location.href;
            strUrlLocation = strUrlLocation.replace('tp-ho-chi-minh/', '').replace('ha-noi/', '');
            var strUrlLink = strPathLink_All.replace('tp-ho-chi-minh/', '').replace('ha-noi/', ''); 
            if (strUrlLocation.toLowerCase().indexOf("/yahoo/") != -1) {
                strUrlLink = strPathLink_All + "yahoo/";
            }
            $('form1').action = strUrlLink + strStateNM + "/buy-deals.aspx?id=" + strIDSP + "&pt=" + iIndex;
            $('form1').submit();
            return false;
        }

}


/*******************************************************************************************/

function BuyDeals_HN(e) {
    var eID = utils.getElementFireEvent(e);
    var flag = 0;
    var iIndex = eID.id.split("_")[1]; 
    
    iIndex = parseInt(iIndex);
    
    
    var strIndex = eID.id.split("_")[1];
    switch (iIndex) {
        case 0:
            //$("txtName_" + iIndex).value = trim($("txtName_" + iIndex).value);
            //$("txtSoNha_" + iIndex).value = trim($("txtSoNha_" + iIndex).value);
            //$("txtDuong_" + iIndex).value = trim($("txtDuong_" + iIndex).value);
            $("txtPhone_" + iIndex).value = trim($("txtPhone_" + iIndex).value);

            if (trim($("txtName_" + iIndex).value).length == 0) {
                flag = 1;
            } else if (trim($("txtSoNha_" + iIndex).value).length == 0) {
                flag = 1;
            }
            else if (trim($("txtDuong_" + iIndex).value).length == 0) {
                flag = 1;
            }
            else if ($("txtPhone_" + iIndex).value.length == 0) {
                flag = 1;
            }
            
            //No.6 21/10
            else if (checkPhone($("txtPhone_" + iIndex).value) == false) {
                $("eMess_" + strIndex).innerHTML = langMess()[0][10];
                return;
            }           
            //No.6 21/10 End

            if ($("ddlDist" + iIndex)) {
                if ($("ddlDist" + iIndex).selectedIndex == 0) {
                    flag = 1;
                }
            }
            else {
                if (trim($("txtQuanHidden_0").value).length == 0)
                    flag = 1;
            }
            /*else if (trim($("txtWard_" + iIndex).value).length == 0) {
            flag = 1;
            }*/

            break;
        case 1:
            if ($("cbGift_1").checked) {
                if (trim($("txtName_1a").value).length == 0)
                    flag = 1;
                else if (trim($("txtSoNha_1a").value).length == 0)
                    flag = 1;
                else if (trim($("txtDuong_1a").value).length == 0)
                    flag = 1;
                else if (trim($("txtName_1b").value).length == 0)
                    flag = 1;
                else if (trim($("txtSoNha_1b").value).length == 0)
                    flag = 1;
                else if (trim($("txtDuong_1b").value).length == 0)
                    flag = 1;

                if ($("dQuanDDL_1")) {//truong hop chua co dia chi trong user_location                   
                    if ($("ddlDist1a").value == "0")
                        flag = 1;
                    if ($("ddlDist1b").value == "0")
                        flag = 1;
                }
                else {//truong hop da co dia chi trong table user_location
                    if (trim($("txtQuanHidden_1a").value).length == 0)
                        flag = 1;
                    if (trim($("txtQuanHidden_1b").value).length == 0)
                        flag = 1;
                }

                if (checkPhone($("txtPhone_1a").value) == false) {
                    $("eMess_1Gift").innerHTML = langMess()[0][10];
                    return;
                } else if (checkPhone($("txtPhone_1b").value) == false) {
                    $("eMess_1Gift").innerHTML = langMess()[0][10];
                    return;
                }

            }
            else {


                if (trim($("txtName_1").value).length == 0)
                    flag = 1;
                
                
                //No.7 21/10
                else if (checkPhone($("txtPhone_" + iIndex).value) == false) {
                    $("eMess_" + strIndex).innerHTML = langMess()[0][10];
                    return;
                }           
                //No.7 21/10 End
                
                else if (trim($("txtSoNha_1").value).length == 0)
                    flag = 1;
                else if (trim($("txtDuong_1").value).length == 0)
                    flag = 1;
                if ($("dQuanDDL_1")) {//truong hop chua co dia chi trong user_location                    
                    if ($("ddlDist1").value == "0")
                        flag = 1;
                }
                else {//truong hop da co dia chi trong table user_location
                    if (trim($("txtQuanHidden_1").value).length == 0)
                        flag = 1;
                }
            }
            break;
        case 2:
            //$("txtName_" + iIndex).value = trim($("txtName_" + iIndex).value);
            $("txtPhone_" + iIndex).value = trim($("txtPhone_" + iIndex).value);
            if (trim($("txtName_" + iIndex).value).length == 0) {
                flag = 1;
            } else if ($("txtPhone_" + iIndex).value.length == 0) {
                flag = 1;
            }
            
            //No.8 21/10
            else if (checkPhone($("txtPhone_" + iIndex).value) == false) {
                $("eMess_" + strIndex).innerHTML = langMess()[0][10];
                return;
            }           
            //No.8 21/10 End
            
            break;
        case 4:
            if ($("cbGift_4").checked) {
                if (trim($("txtName_4a").value).length == 0)
                    flag = 1;
                else if (trim($("txtSoNha_4a").value).length == 0)
                    flag = 1;
                else if (trim($("txtDuong_4a").value).length == 0)
                    flag = 1;
                else if (trim($("txtName_4b").value).length == 0)
                    flag = 1;
                else if (trim($("txtSoNha_4b").value).length == 0)
                    flag = 1;
                else if (trim($("txtDuong_4b").value).length == 0)
                    flag = 1;

                if ($("dQuanDDL_4")) {//truong hop chua co dia chi trong user_location
                    if ($("ddlDist4a").value == "0")
                        flag = 1;
                    if ($("ddlDist4b").value == "0")
                        flag = 1;
                }
                else {//truong hop da co dia chi trong table user_location
                    if (trim($("txtQuanHidden_4a").value).length == 0)
                        flag = 1;
                    if (trim($("txtQuanHidden_4b").value).length == 0)
                        flag = 1;
                }

                if (checkPhone($("txtPhone_4a").value) == false) {
                    $("eMess_4Gift").innerHTML = langMess()[0][10];
                    return;
                } else if (checkPhone($("txtPhone_4b").value) == false) {
                    $("eMess_4Gift").innerHTML = langMess()[0][10];
                    return;
                }


            }
            else {
                if (trim($("txtName_4").value).length == 0)
                    flag = 1;
                    
                
                //No.9 21/10
                else if (checkPhone($("txtPhone_" + iIndex).value) == false) {
                    $("eMess_" + strIndex).innerHTML = langMess()[0][10];
                    return;
                }           
                //No.9 21/10 End
                
                    
                else if (trim($("txtSoNha_4").value).length == 0)
                    flag = 1;
                else if (trim($("txtDuong_4").value).length == 0)
                    flag = 1;
                if ($("dQuanDDL_4")) {//truong hop chua co dia chi trong user_location
                    if ($("ddlDist4").value == "0")
                        flag = 1;
                }
                else {//truong hop da co dia chi trong table user_location
                    if (trim($("txtQuanHidden_4").value).length == 0)
                        flag = 1;
                }
            }
            break;
        case 5:
            if ($("cbGift_5").checked) {
                if (trim($("txtName_5a").value).length == 0)
                    flag = 1;
                else if (trim($("txtSoNha_5a").value).length == 0)
                    flag = 1;
                else if (trim($("txtDuong_5a").value).length == 0)
                    flag = 1;
                else if (trim($("txtName_5b").value).length == 0)
                    flag = 1;
                else if (trim($("txtSoNha_5b").value).length == 0)
                    flag = 1;
                else if (trim($("txtDuong_5b").value).length == 0)
                    flag = 1;

                if ($("dQuanDDL_5")) {//truong hop chua co dia chi trong user_location
                    if ($("ddlDist5a").value == "0")
                        flag = 1;
                    if ($("ddlDist5b").value == "0")
                        flag = 1;
                }
                else {//truong hop da co dia chi trong table user_location
                    if (trim($("txtQuanHidden_5a").value).length == 0)
                        flag = 1;
                    if (trim($("txtQuanHidden_5b").value).length == 0)
                        flag = 1;
                }


                if (checkPhone($("txtPhone_4a").value) == false) {
                    $("eMess_4Gift").innerHTML = langMess()[0][10];
                    return;
                } else if (checkPhone($("txtPhone_4b").value) == false) {
                    $("eMess_4Gift").innerHTML = langMess()[0][10];
                    return;
                }


            }
            else {
                if (trim($("txtName_5").value).length == 0)
                    flag = 1;
                
                //No.10 21/10
                else if (checkPhone($("txtPhone_" + iIndex).value) == false) {
                    $("eMess_" + strIndex).innerHTML = langMess()[0][10];
                    return;
                }           
                //No.10 21/10 End
                
                else if (trim($("txtSoNha_5").value).length == 0)
                    flag = 1;
                else if (trim($("txtDuong_5").value).length == 0)
                    flag = 1;
                if ($("dQuanDDL_5")) {//truong hop chua co dia chi trong user_location
                    if ($("ddlDist5").value == "0")
                        flag = 1;
                }
                else {//truong hop da co dia chi trong table user_location
                    if (trim($("txtQuanHidden_5").value).length == 0)
                        flag = 1;
                }
            }
            break;
    }

    if (flag == 1) 
        {
            $("eMess_" + strIndex).innerHTML = langMess()[0][5];
        }

        else 
        {
            var strUrlLocation = window.location.href;
            strUrlLocation = strUrlLocation.replace('tp-ho-chi-minh/', '').replace('ha-noi/', '');
            var strUrlLink = strPathLink_All.replace('tp-ho-chi-minh/', '').replace('ha-noi/', ''); 
            if (strUrlLocation.toLowerCase().indexOf("/yahoo/") != -1) {
                strUrlLink = strPathLink_All + "yahoo/";
            }
            var st = getQueryStringValue("st");
            var idsp = getQueryStringValue("id");
            //$('form1').action = "?st=" + st + "&id=" + idsp + "&pt=" + iIndex;
            $('form1').action = strUrlLink + strStateNM + "/buy-deals-hn.aspx?id=" + strIDSP + "&pt=" + iIndex;
            $('form1').submit();
            
            return false;
        }   
}


/***********Tinh Tong GIa tri tien khi chon so luong mua**********/
function ThanhTien() {
    var iSLMua = $("DDL_SLMua").value;
    var iGiaBan = $("iGiaBan").innerHTML;
    iGiaBan = iGiaBan.replace(".", "");
    var iThanhTien = iGiaBan * iSLMua;
    $("iThanhTien").innerHTML = number_format(iThanhTien, 2, '.', '.');
}

function number_format(number, decimals, dec_point, thousands_sep) {
    // Formats a number with grouped thousands
    //
    // version: 906.1806
    // discuss at: http://phpjs.org/functions/number_format
    // +   original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     bugfix by: Michael White (http://getsprink.com)
    // +     bugfix by: Benjamin Lupton
    // +     bugfix by: Allan Jensen (http://www.winternet.no)
    // +    revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +     bugfix by: Howard Yeend
    // +    revised by: Luke Smith (http://lucassmith.name)
    // +     bugfix by: Diogo Resende
    // +     bugfix by: Rival
    // +     input by: Kheang Hok Chin (http://www.distantia.ca/)
    // +     improved by: davook
    // +     improved by: Brett Zamir (http://brett-zamir.me)
    // +     input by: Jay Klehr
    // +     improved by: Brett Zamir (http://brett-zamir.me)
    // +     input by: Amir Habibi (http://www.residence-mixte.com/)
    // +     bugfix by: Brett Zamir (http://brett-zamir.me)
    // *     example 1: number_format(1234.56);
    // *     returns 1: '1,235'
    // *     example 2: number_format(1234.56, 2, ',', ' ');
    // *     returns 2: '1 234,56'
    // *     example 3: number_format(1234.5678, 2, '.', '');
    // *     returns 3: '1234.57'
    // *     example 4: number_format(67, 2, ',', '.');
    // *     returns 4: '67,00'
    // *     example 5: number_format(1000);
    // *     returns 5: '1,000'
    // *     example 6: number_format(67.311, 2);
    // *     returns 6: '67.31'
    // *     example 7: number_format(1000.55, 1);
    // *     returns 7: '1,000.6'
    // *     example 8: number_format(67000, 5, ',', '.');
    // *     returns 8: '67.000,00000'
    // *     example 9: number_format(0.9, 0);
    // *     returns 9: '1'
    // *     example 10: number_format('1.20', 2);
    // *     returns 10: '1.20'
    // *     example 11: number_format('1.20', 4);
    // *     returns 11: '1.2000'
    // *     example 12: number_format('1.2000', 3);
    // *     returns 12: '1.200'
    var n = number, prec = decimals;

    var toFixedFix = function(n, prec) {
        var k = Math.pow(10, prec);
        return (Math.round(n * k) / k).toString();
    };

    n = !isFinite(+n) ? 0 : +n;
    prec = !isFinite(+prec) ? 0 : Math.abs(prec);
    var sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep;
    var dec = (typeof dec_point === 'undefined') ? '.' : dec_point;

    var s = (prec > 0) ? toFixedFix(n, prec) : toFixedFix(Math.round(n), prec); //fix for IE parseFloat(0.55).toFixed(0) = 0;

    var abs = toFixedFix(Math.abs(n), prec);
    var _, i;

    if (abs >= 1000) {
        _ = abs.split(/\D/);
        i = _[0].length % 3 || 3;

        _[0] = s.slice(0, i + (n < 0)) +
          _[0].slice(i).replace(/(\d{3})/g, sep + '$1');
        s = _.join(dec);
    } else {
        s = s.replace('.', dec);
    }

    var decPos = s.indexOf(dec);
    if (prec >= 1 && decPos !== -1 && (s.length - decPos - 1) < prec) {
        s += new Array(prec - (s.length - decPos - 1)).join(0) + '0';
    }
    else if (prec >= 1 && decPos === -1) {
        s += dec + new Array(prec).join(0) + '0';
    }
    return s;
}


/***************************************************************/
var iPTTT = 0;
function showFormBuy(e) {
    var eID = utils.getElementFireEvent(e);
    //iPTTT = eID.up("li").down("a").id.split("_")[1];
    iPTTT = eID.parentNode.id.split("_")[1];
	$("liPTTT_0").style.display = "none";
	$("liPTTT_2").style.display = "none";
    $("liGift_1").style.display = "none";
	$("liNoGift_1").style.display = "none";
	$("liGift_4").style.display = "none";
	$("liNoGift_4").style.display = "none";
	$("liGift_4").style.display = "none";
	$("liNoGift_4").style.display = "none";
	$("liGift_5").style.display = "none";
	$("liNoGift_5").style.display = "none";

	checkbtn_0.removeClassName('checked');
	checkbtn_1.removeClassName('checked');
	checkbtn_2.removeClassName('checked');
	checkbtn_4.removeClassName('checked');
	checkbtn_5.removeClassName('checked');
	
	if(iPTTT ==0){
		$("liPTTT_0").style.display = "block";		
	}
	else if(iPTTT == 2){
		$("liPTTT_2").style.display = "block";
	}
	else{
		$("liNoGift_"+iPTTT).style.display = "block";
}
switch (parseInt(iPTTT)) {
    case 0: checkbtn_0.addClassName('checked'); break;
    case 1: checkbtn_1.addClassName('checked'); break;
    case 2: checkbtn_2.addClassName('checked'); break;
    case 4: checkbtn_4.addClassName('checked'); break;
    case 5: checkbtn_5.addClassName('checked'); break;
    
}	
}
/***************************************************************/
function showFormBuy_HN(e) {
    var eID = utils.getElementFireEvent(e);
    //iPTTT = eID.up("li").down("a").id.split("_")[1];
    iPTTT = eID.parentNode.id.split("_")[1];
    $("liPTTT_0").style.display = "none";
    $("liPTTT_2").style.display = "none";
    $("liGift_1").style.display = "none";
    $("liNoGift_1").style.display = "none";
    $("liGift_4").style.display = "none";
    $("liNoGift_4").style.display = "none";
    $("liGift_4").style.display = "none";
    $("liNoGift_4").style.display = "none";
    $("liGift_5").style.display = "none";
    $("liNoGift_5").style.display = "none";

    checkbtn_0.removeClassName('checked');
    checkbtn_1.removeClassName('checked');
    checkbtn_2.removeClassName('checked');
    checkbtn_4.removeClassName('checked');
    checkbtn_5.removeClassName('checked');

    if (iPTTT == 0) {
        $("liPTTT_0").style.display = "block";
    }
    else if (iPTTT == 2) {
        $("liPTTT_2").style.display = "block";
    }
    else {
        $("liNoGift_" + iPTTT).style.display = "block";
    }
    switch (parseInt(iPTTT)) {
        case 0: checkbtn_0.addClassName('checked'); break;
        case 1: checkbtn_1.addClassName('checked'); break;
        case 2: checkbtn_2.addClassName('checked'); break;
        case 4: checkbtn_4.addClassName('checked'); break;
        case 5: checkbtn_5.addClassName('checked'); break;

    }	    
}



/***************************************************************/
var GiftFlag_1 = 0, GiftFlag_4 = 0, GiftFlag_5 = 0;
function showInfoGift(value) {
    if (value.id == "dCheckNoGift_1" || value.id == "dCheckGift_1") 
	{        
		if($("liNoGift_1").style.display == "block")
		{
			$("liNoGift_1").style.display = "none";
			$("liGift_1").style.display = "block";
			$("cbGift_1").checked = true;
		}
		else{
			$("liNoGift_1").style.display = "block";
			$("liGift_1").style.display = "none";
			$("cbGift_1").checked = false;
		}
		
    }
	else if (value.id == "dCheckNoGift_4" || value.id == "dCheckGift_4") {
	if ($("liNoGift_4").style.display == "block")
		{
			$("liNoGift_4").style.display = "none";
			$("liGift_4").style.display = "block";
			$("cbGift_4").checked = true; 
        }
		else{
			$("liNoGift_4").style.display = "block";
			$("liGift_4").style.display = "none";
			$("cbGift_4").checked = false; 
		}
	}
	else if (value.id == "dCheckNoGift_5" || value.id == "dCheckGift_5") 
	{
		if($("liNoGift_5").style.display == "block")
		{
			$("liNoGift_5").style.display = "none";
			$("liGift_5").style.display = "block";
			$("cbGift_5").checked = true;
		}
		else
		{
			$("liNoGift_5").style.display = "block";
			$("liGift_5").style.display = "none";
			$("cbGift_5").checked = false; 
		}
	}
    
    
    //-------------------
    //them su kien onclick
    if ($("btnTT_1Gift")) $("btnTT_1Gift").onclick = BuyDeals;
    if ($("btnTT_4Gift")) $("btnTT_4Gift").onclick = BuyDeals;
    if ($("btnTT_5Gift")) $("btnTT_5Gift").onclick = BuyDeals;

    if ($("btnTTHN_1Gift")) $("btnTTHN_1Gift").onclick = BuyDeals_HN;
    if ($("btnTTHN_4Gift")) $("btnTTHN_4Gift").onclick = BuyDeals_HN;
    if ($("btnTTHN_5Gift")) $("btnTTHN_5Gift").onclick = BuyDeals_HN;

    //-----------------------

}


function setNoneAllPTTT() {
    $("liPTTT_0").style.display = "none";
    $("liGift_1").style.display = "none";
    $("liNoGift_1").style.display = "none";
    $("liPTTT_2").style.display = "none";
    if ($("btnTT_4")) {
        $("liGift_4").style.display = "none";
        $("liNoGift_4").style.display = "none";
    }
    if ($("btnTT_5")) {
        $("liGift_5").style.display = "none";
        $("liNoGift_5").style.display = "none";
    }

    checkbtn_0.removeClassName('checked');
    checkbtn_1.removeClassName('checked');
    checkbtn_2.removeClassName('checked');
    checkbtn_4.removeClassName('checked');
    checkbtn_5.removeClassName('checked');
}
function setNoneAllPTTT_HN() {
    $("liPTTT_0").style.display = "none";
    $("liGift_1").style.display = "none";
    $("liNoGift_1").style.display = "none";
    $("liPTTT_2").style.display = "none";
    if ($("btnTTHN_4")) {
        $("liGift_4").style.display = "none";
        $("liNoGift_4").style.display = "none";
    }
    if ($("btnTTHN_5")) {
        $("liGift_5").style.display = "none";
        $("liNoGift_5").style.display = "none";
    }

    checkbtn_0.removeClassName('checked');
    checkbtn_1.removeClassName('checked');
    checkbtn_2.removeClassName('checked');
    checkbtn_4.removeClassName('checked');
    checkbtn_5.removeClassName('checked');
}

function getQueryStringValue(value) {

    var listQuery = new Array();
    var query_value = "";
    listQuery = window.location.search.substring(1).split('&');
    for (var i = 0; i < listQuery.length; i++) {
        if (listQuery[i].indexOf(value) != -1) {
            query_value = listQuery[i].split('=')[1];
        }
    }

    return query_value;

}

